package com.me.jingdongshop.ui.activity;

import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.stellarmap.StellarMap;
import com.me.common.base.BaseActivity;
import com.me.jingdongshop.R;
import com.me.jingdongshop.model.bean.HomeRecommendedBrand;
import com.me.jingdongshop.model.protocol.IHttpService;
import com.me.jingdongshop.presenter.TestFragmentPre;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuer on 2017/5/7/007.
 * 推荐品牌
 */
public class HomeRecommendedBrandActivity extends BaseActivity {
    private ImageView ivHeadBack;
    private HomeRecommendedBrand homeRecommendedBrand;
    private List<HomeRecommendedBrand.BrandBean> myBrandBeen;
    List<List<HomeRecommendedBrand.BrandBean>> list;
    private StellarMap mStellarMap;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_home_recommended_brand;
    }

    @Override
    public void initView() {
        mStellarMap = findView(R.id.stellarMap);
        ivHeadBack = (ImageView) findViewById(R.id.iv_head_back);
        ivHeadBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    public void initListener() {

    }

    TestFragmentPre mTestFragmentPre;

    @Override
    public void initData() {
        mTestFragmentPre = new TestFragmentPre(this);
        mTestFragmentPre.getBrandData();
    }

    @Override
    public void onClick(View v, int id) {

    }

    @Override
    public void onHttpSuccess(int reqType, Message msg) {
        if (reqType == IHttpService.HTTP_BRAND) {
            homeRecommendedBrand = (HomeRecommendedBrand) msg.obj;
            myBrandBeen = homeRecommendedBrand.getBrand();
            list = new ArrayList<>();
            list.add(myBrandBeen);
            final List<String> datas = new ArrayList<>();
            for (int i = 0; i < myBrandBeen.size(); i++) {
                HomeRecommendedBrand.BrandBean brandBean = myBrandBeen.get(i);
                List<HomeRecommendedBrand.BrandBean.ValueBean> value = brandBean.getValue();
                for (int j = 0; j < value.size(); j++) {
                    HomeRecommendedBrand.BrandBean.ValueBean valueBean = value.get(j);
                    String name = valueBean.getName();
                    datas.add(name);
                }
            }

            mStellarMap.setAdapter(new StellarMap.Adapter() {
                @Override
                public int getCount() {
                    return datas.size();
                }

                @Override
                protected View getView(int index, View convertView) {
                    TextView textView = new TextView(HomeRecommendedBrandActivity.this);
                    textView.setText(datas.get(index));
                    return textView;
                }
            });
        }
    }

    @Override
    public void onHttpError(int reqType, String error) {

    }
}
